#!/bin/bash

# 系统Python的版本检查和安装、配置，以及第三方包的安装

# 安装Python-2.7
function InstallPython() {
	rm -rf Python-2.7.10
	unzip Python-2.7.10.zip

	cd Python-2.7.10
	chmod +x *
	mkdir /usr/local/python2.7
	make install

	cd ..
}

# 检查现在的版本
pythonVer="0.0"
if [ "$(which python2 2> /dev/null)" != "" ]; then
	pythonVer=$(python2 -V 2>&1 | cut -d\  -f2)
fi
if [ "${pythonVer}" \< "2.7.0" ]; then
	echo "Python Version ${pythonVer} Older than 2.7, now install a Python-2.7.10 from tar package"
	InstallPython
else
	echo "Python Version ${pythonVer}, no need to install another Python"
fi

# Python site-packages
# Config site path
if [ "$(grep /usr/local/lib/python2.7/site-packages /etc/profile)" == "" ]; then
	export PYTHONPATH=/usr/local/lib/python2.7/site-packages
	cat >> /etc/profile << EOF

# added by zw 2017/8/19 for custom python2.7 site-packages path
export PYTHONPATH=/usr/local/lib/python2.7/site-packages
EOF
	echo "Add custom python2.7 site-packages path"
else
	echo "Custom python2.7 site-packages path already exists"
fi

# install 3rd packages
# xlrd xlwt XlsxWriter rarfile
cd packages

#echo ">>>>>>>>Install Python::xlrd"
#rm -rf xlrd-0.9.3
#unzip -qq xlrd-0.9.3.zip
#tar -xf xxxx.tar.gz
#cd xlrd-0.9.3/xlrd-0.9.3
#chmod +x setup.py
#python2 setup.py install > /dev/null
#cd ../..

cd ..

